<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta content="telephone=no" name="format-detection" />
    <!-- 留作将来统一添加 -->
    <TEMPLATE>${TEMPLATE}</TEMPLATE>
    <title>个人报告-学生</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../css/index.css">
    <link rel="stylesheet" type="text/css" href="../../css/data-flex.min.css">
    <style type="text/css">
        body {
            background: rgba(90, 194, 255, 1);
        }
        
        .wrapper {
            padding: 4px 15px;
            height: 100vh;
        }
        
        .select {
            z-index: 1;
            position: relative;
            height: 50px;
            background: rgba(255, 255, 255, 1);
            box-shadow: 0px 4px 10px 0px rgba(0, 135, 214, 0.37);
            border-radius: 10px;
            padding: 10px 0;
            overflow: visible;
        }
        
        .select-item {
            min-width: 33.3%;
            height: 30px;
            border-left: 1px solid #bfbfbf;
        }

        .select-item:first-child {
            border-left: none;
        }
        
        .select-item-txt {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            font-weight: bold;
            color: rgba(25, 25, 25, 1);
            font-size: 15px;
        }
        
        .select-item-img {
            min-width: 16px;
            width: 16px;
            height: 16px;
            margin-left: 5px;
        }
        
        .layer {
            position: absolute;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
        }
        
        .downdrop {
            position: absolute;
            left: 0;
            top: 60px;
            width: 100%;
            max-height: 275px;
            overflow-y: auto;
            padding: 0 11px;
            background: rgba(255, 255, 255, 1);
            border-radius: 10px;
        }
        
        .downdrop-item {
            position: relative;
            height: 50px;
            border-right: 0;
        }

        .downdrop-item::after {
            content: "";
            position: absolute;
            left: 0;
            top: 0;
            width: 100%;
            height: 1px;
            transform: scaleY(0.5);
            background-color: rgba(212, 212, 212, 1);
        }
        
        .downdrop-item:first-child::after {
            display: none;
        }
        
        .downdrop-item-txt {
            font-size: 15px;
            font-weight: 400;
            color: rgba(25, 25, 25, 1);
        }
        
        .downdrop-item-img {
            width: 17px;
            height: 17px;
        }
        
        .content {
            margin-top: 20px;
            padding: 22px 15px 31px 15px;
            background: rgba(255, 255, 255, 1);
            box-shadow: 0px 4px 10px 0px rgba(0, 135, 214, 0.37);
            border-radius: 10px;
        }
        
        .head {
            height: 20px;
            margin-bottom: 25px;
        }
        
        .head-txt {
            font-size: 13px;
            font-weight: 400;
            color: rgba(25, 25, 25, 1);
        }
        
        .cir1 {
            width: 14px;
            height: 14px;
            background: rgba(253, 155, 67, 1);
            border-radius: 50%;
            margin-right: 5px;
        }
        
        .cir2 {
            width: 14px;
            height: 14px;
            background: rgba(90, 194, 255, 1);
            border-radius: 50%;
            margin-right: 5px;
        }
        
        .row {
            margin-bottom: 20px;
        }
        
        .row:last-of-type {
            margin-bottom: 0;
        }
        
        .row-title {
            max-width: 85px;
            font-size: 13px;
            font-weight: bold;
            color: rgba(25, 25, 25, 1);
            margin-right: 10px;
            text-align: left;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        
        .columnar-1 {
            height: 14px;
            background: linear-gradient(90deg, rgba(147, 227, 255, 1) 0%, rgba(90, 194, 255, 1) 100%);
            border-radius: 0px 100px 100px 0px;
        }
        
        .columnar-2 {
            height: 14px;
            background: linear-gradient(90deg, rgba(255, 207, 163, 1) 0%, rgba(253, 155, 67, 1) 100%);
            border-radius: 0px 100px 100px 0px;
        }
        
        .fraction {
            font-size: 12px;
            font-weight: 500;
            color: rgba(25, 25, 25, 1);
            min-width: fit-content;
            text-align: left;
            text-indent: 5px;
        }
        
        .active {
            color: rgba(90, 194, 255, 1) !important;
        }
    </style>
</head>

<body>
    <div class="vueApp" v-cloak>
        <div v-show="downdrop.open" class="layer" @click="closeDowndrop"></div>
        <div class="wrapper">
            <div class="select" data-flex="main:justify">
                <div class="select-item" v-if="type == 2 && from != 'student'" data-flex-box="1" @click="changeStatus(1)" data-flex="main:center cross:center">
                    <div class="select-item-txt" :class="{active: downdrop.index === 1}">{{ option.currentClass.text }}</div>
                    <img class="select-item-img" :src="downdrop.index === 1 ? '../../image/course/arrow2.png' : '../../image/course/arrow.png'" alt="">
                </div>
                <div class="select-item" data-flex-box="1" @click="changeStatus(2)" data-flex="main:center cross:center">
                    <div class="select-item-txt" :class="{active: downdrop.index === 2}">{{ option.currentCourse.text }}</div>
                    <img class="select-item-img" :src="downdrop.index === 2 ? '../../image/course/arrow2.png' : '../../image/course/arrow.png'" alt="">
                </div>
                <div class="select-item" data-flex-box="1" @click="changeStatus(3)" data-flex="main:center cross:center">
                    <div class="select-item-txt" :class="{active: downdrop.index === 3}">{{ option.currentUnit.text }}</div>
                    <img class="select-item-img" :src="downdrop.index === 3 ? '../../image/course/arrow2.png' : '../../image/course/arrow.png'" alt="">
                </div>
                <div v-show="downdrop.index === 1" class="downdrop" @click="closeDowndrop">
                    <div v-for="item,index in option.classData" class="downdrop-item" data-flex="main:justify cross:center" @click="toggleClass(index)">
                        <div class="downdrop-item-txt">{{ item.name }}</div>
                        <img class="downdrop-item-img" v-show="option.currentClass.code == item.id" src="../../image/course/checked2.png" alt="">
                    </div>
                </div>
                <div v-show="downdrop.index === 2" class="downdrop" @click="closeDowndrop">
                    <div v-for="item,index in option.courseData" class="downdrop-item" data-flex="main:justify cross:center" @click="toggleCourse(index)">
                        <div class="downdrop-item-txt">{{ item.name }}</div>
                        <img class="downdrop-item-img" v-show="option.currentCourse.code == item.id" src="../../image/course/checked2.png" alt="">
                    </div>
                </div>
                <div v-show="downdrop.index === 3" class="downdrop" @click="closeDowndrop">
                    <div v-for="item,index in option.unitData" class="downdrop-item" data-flex="main:justify cross:center" @click="toggleUnit(index)">
                        <div class="downdrop-item-txt">{{ item.name }}</div>
                        <img class="downdrop-item-img" v-show="option.currentUnit.code == item.id" src="../../image/course/checked2.png" alt="">
                    </div>
                </div>
            </div>
            <div class="content">
                <div class="head" data-flex="main:left cross:center">
                    <div class="head-txt" data-flex-box="8">{{ type == 1 || from == 'student' ? '个人/班级对比图' : '班级对比图' }}</div>
                    <div data-flex="cross:center main:right" data-flex-box="1">
                        <div class="cir1"></div>
                        <div class="head-txt">班级</div>
                    </div>
                    <div data-flex="cross:center main:right" v-if="type == 1 || from == 'student'" data-flex-box="1">
                        <div class="cir2"></div>
                        <div class="head-txt">个人</div>
                    </div>
                </div>
                <div v-for="item,index in scoreData" class="row" data-flex="cross:center box:first" @click="handleChart(index)">
                    <div class="row-title">{{ item.questionTypeName || item.catalogName }}</div>
                    <div>
                        <div data-flex="main:left cross:center" v-if="item.stuScoreValue > 0">
                            <div :style="'width:' + item.stuScoreValue + '%'" class="columnar-1"></div>
                            <div class="fraction">{{item.stuScoreValue}}分</div>
                        </div>
                        <div data-flex="main:left cross:center" v-if="item.classScoreValue > 0">
                            <div :style="'width:' + item.classScoreValue + '%'" class="columnar-2"></div>
                            <div class="fraction">{{item.classScoreValue}}分</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/service/service-tool.js"></script>
<script type="text/javascript" src="../../script/service/service-app.js"></script>
<script type="text/javascript" src="../../script/service/service-user.js"></script>
<script type="text/javascript" src="../../script/service/service-logic.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript">
    // html 的引号一律为双引号(""),js 为单引号('')
    var USER, $S, vm;
    var pageParam = {};
    // reportType 
    // 1 习题报告 学生(个人和班级平均分->错题详情),老师(班级平均分->班级平均分，学生列表) from index&class
    // 2 跟读报告 学生(个人和班级平均分->跟读详情,分类列表),老师(班级平均分->班级平均分，学生列表) from index&class
    // 3 习题报告，老师查看个人习题报告  有全部学期和单元,逻辑同1的学生 from student
    // 4 跟读报告，老师查看个人跟读报告  有全部学期和单元,逻辑同2的学生 from student
    // from
    // index 首页
    // class 班级详情
    // student 学生详情
    var custId = '', classId = '';
    apiready = function() {
        $S = SERVICE();
        USER = USER();
        console.log(JSON.stringify(api.pageParam) + '=====pageParam');
        pageParam = api.pageParam;
        custId = USER.Get('custId');
        classId  = USER.Get('classId');
        fnInit();
    };
    // 初始化
    function fnInit() {
        vm = new Vue({
            el: '.vueApp',
            data: {
                type: USER.Get('memberType', true),
                from: pageParam.from,
                reportType: pageParam.reportType,
                // 下拉相关
                downdrop: {
                    // 当前选中
                    index: 0,
                    // 上一个选中
                    prevIndex: 0,
                    // 是否展开下拉列表
                    open: false,
                },
                // 选项相关
                option: {
                    currentCourse: {
                        text: pageParam.courseText || '',
                        code: pageParam.courseCode || ''
                    },
                    currentUnit: {
                        text: pageParam.unitText || '',
                        code: pageParam.unitCode || ''
                    },
                    currentClass: {
                        text: pageParam.classText || '',
                        code: pageParam.classCode || ''
                    },
                    courseIndex: pageParam.courseIndex || '',
                    unitIndex: pageParam.unitIndex || '',
                    classIndex: pageParam.classIndex || '',
                    courseData: pageParam.semesterData || [],
                    classData: pageParam.classData || [],
                    unitData: '' 
                },
                scoreData: []
            },
            methods: {
                changeStatus: function(index) {
                    // 判断当前点击的和上一次点击的是不是同一个元素
                    var isPrev = index === this.downdrop.prevIndex ? true : false;
                    this.downdrop.prevIndex = index;
                    if (isPrev) {
                        // 如果是就关闭
                        this.downdrop.open = false;
                        this.downdrop.index = 0;
                        this.downdrop.prevIndex = 0;
                    } else {
                        // 如果不是就切换
                        this.downdrop.open = true;
                        this.downdrop.index = index;
                    }
                },
                toggleClass: function(index) {
                    // 选择班级
                    this.option.classIndex = index;
                    this.option.currentClass.text = this.option.classData[index].name;
                    this.option.currentClass.code = this.option.classData[index].id;
                    classId = this.option.currentClass.code;
                    getChartData();
                },
                toggleCourse: function(index) {
                    // 选择课程
                    this.option.courseIndex = index;
                    this.option.currentCourse.text = this.option.courseData[index].name;
                    this.option.currentCourse.code = this.option.courseData[index].id;
                },
                toggleUnit: function(index) {
                    // 选择单元
                    if(this.option.currentCourse.code) {
                        this.option.unitIndex = index;
                        this.option.currentUnit.text = this.option.unitData[index].name;
                        this.option.currentUnit.code = this.option.unitData[index].id;
                        getChartData();
                    }else {
                        if(this.from == 'student') {
                            getChartData();
                        }else {
                            fnToast('请先选择课程');
                        }
                    }
                }
            },
            watch: {
                'option.courseIndex': function() {
                    getUnitsData();
                    this.downdrop.open = true;
                    this.downdrop.index = 3;
                    this.downdrop.prevIndex = 3;
                    this.option.currentUnit.text = '请选择单元';
                    this.option.currentUnit.code = '';
                }
            }
        });
        if(pageParam.from == 'student') {
            // 老师查看学生,全部学期
            custId = pageParam.custId;
            vm.option.currentUnit = {text: '全部单元', code: ''};
            classId = pageParam.classId;
            getCourseList();
        }else if(pageParam.from == 'class') {
            classId = pageParam.classCode;
        }else if(pageParam.from == 'index' && vm.type == 2) {
            classId = pageParam.classCode;
        }
        if(pageParam.from != 'student') {
            getUnitsData();
        }
        getChartData();
    }

    // 获取小节数据
    function getUnitsData() {
        var url = 'course/findCourseChild';
        var params = {
            'courseParentId': vm.option.currentCourse.code
        };
        var callback = function(data) {
            var arr = [];
            if(pageParam.from == 'student') {
                // 老师查看学生,全部单元
                arr = [{name: '全部单元', id: ''}];
                vm.option.currentUnit = {text: '全部单元', code: ''};
            }
            data.listData.forEach(function(item) {
                arr.push(
                    {
                        name: item.courseName,
                        id: item.id
                    }
                );
            });
            vm.option.unitData = arr;
        };
        POST(url, params, callback);
    }

    // 教材列表
    function getCourseList() {
        var url = 'course/findIndexCourseList';
        var params = {};
        var callback = function(data) {
            var arr = [];
            if(pageParam.from == 'student') {
                // 老师查看学生,全部单元
                arr = [{name: '全部学期', id: ''}];
                vm.option.currentCourse = {text: '全部学期', code: ''};
            }
            data.listData.forEach(function(item) {
                arr.push(
                    {
                        name: item.courseName,
                        id: item.id
                    }
                );
            });
            vm.option.courseData = arr;
            // status 为200时,只返回data
        };
        POST(url, params, callback);
    }

    // 获取图表数据
    function getChartData() {
        var url = 'courseReport/findExercisesReport';
        var params = {
            reportType: ';1;3;'.indexOf(';'+pageParam.reportType+';') != -1 ? '1' : '6',
            unitId: vm.option.currentUnit.code,
            courseId: vm.option.currentCourse.code,
            queryStudentId: '',
            queryClassesId: classId,
            questionTypeCode: ''
        };
        if(vm.type == 1 || pageParam.from == 'student') {
            // 学生
            params.queryStudentId = custId;
        }else {
            params.queryStudentId = '';
        }
        if(params.reportType == '6') {
            params.questionTypeCode = '42';
        }
        var callback = function(data) {
            var listData = data.listData;
            for(var i = 0; i < listData.length; i ++) {
                var item = listData[i];
                // 如果非整数的话保留两位小数
                if(Number(item.stuScoreValue) % 1 !== 0) {
                    item.stuScoreValue = Number(item.stuScoreValue).toFixed(2);
                }
                if(Number(item.classScoreValue) % 1 !== 0) {
                    item.classScoreValue = Number(item.classScoreValue).toFixed(2);
                }
            }
            vm.scoreData = data.listData;
            vm.$nextTick(function() {
                var arr = [];
                var el = document.getElementsByClassName('row-title');
                for(item of el) {
                    // 注意 80 为 css 中的最大宽度, 如果最大宽度发生改变, 该值也应当改变
                    if(item.offsetWidth <= 85) {
                        arr.push(item.offsetWidth);
                    }
                }
                var max = Math.max.apply(null, arr);
                for(item of el) {
                    item.style.minWidth = max + 'px';
                }
            });
        };
        POST(url, params, callback);
    }

    function handleChart(index) {
        var item = vm.scoreData[index];
        if(vm.type == 1) {
            // 学生 错题列表
            if(pageParam.reportType == 1) {
                // 学习报告，查看错题
                var params = {
                    name: 'question_list_win',
                    url: '../question/question_error.html',
                    slidBackEnabled: false,
                    pageParam: {
                        name: item.questionTypeName,
                        id: vm.option.currentUnit.code,
                        code: item.questionTypeCode,
                        frameName: api.frameName,
                        winName: api.winName
                    }
                };
                fnOpenWin(params);
            }else if(pageParam.reportType == 2) {
                // 跟读，查看跟读列表
                fnOpenPublicWin('跟读报告', 'course1/read_list', {
                    id: item.catalogId,
                    code: item.questionTypeCode,
                    report: '1'
                });
            }
        }else if(vm.type == 2) {
            // 老师
            if(pageParam.from == 'index' || pageParam.from == 'class') {
                var title = pageParam.reportType == 1 ? '学习报告' : '跟读报告';
                fnOpenPublicWin(title, 'class/review_data', {
                    reportType: pageParam.reportType == 1 ? 7 : 8,
                    from: 'class',
                    classId: vm.option.currentClass.code,
                    unitId: vm.option.currentUnit.code,
                    catalogId: item.catalogId,
                    score: item.classScoreValue
                });
            }else if(pageParam.from == 'student') {
                var title = pageParam.reportType == 3 ? '学习报告' : '跟读报告';
                fnOpenPublicWin(title, 'class/review_data', {
                    reportType: pageParam.reportType == 3 ? 3 : 5,
                    from: 'class',
                    classId: classId,
                    custId: custId,
                    catalogId: item.catalogId,
                    questionTypeCode: item.questionTypeCode
                });
            }
        }
    }

    // 
    function handleRightBtn() {
        pageParam.isBtn = false;
        pageParam.error = '1';
        pageParam.reload = true;
        fnOpenPublicWin('错题集', 'class/select_model', pageParam);
    }

    // 关闭下拉列表
    function closeDowndrop() {
        vm.downdrop.open = false;
        vm.downdrop.index = 0;
        vm.downdrop.prevIndex = 0;
    }
</script>

</html>